/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ar.uba.fi.posgrado.common.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Transactional;

import ar.uba.fi.posgrado.common.dao.DAOException;
import ar.uba.fi.posgrado.common.dao.IdTypeDAO;
import ar.uba.fi.posgrado.common.exception.MissingArgumentException;
import ar.uba.fi.posgrado.common.exception.PosgradoException;
import ar.uba.fi.posgrado.common.exception.PosgradoRuntimeException;
import ar.uba.fi.posgrado.common.model.IdentificationType;
import ar.uba.fi.posgrado.common.model.User;
import ar.uba.fi.posgrado.common.service.IdentificationTypeService;

public class IdentificationTypeServiceImpl implements IdentificationTypeService {

	private static Logger logger = Logger
			.getLogger(IdentificationTypeServiceImpl.class);

	private IdTypeDAO idTypeDAO;

	/**
	 * @return the idTypeDAO
	 */
	public IdTypeDAO getIdTypeDAO() {
		return idTypeDAO;
	}

	/**
	 * @param idTypeDAO
	 *            the idTypeDAO to set
	 */
	public void setIdTypeDAO(IdTypeDAO idTypeDAO) {
		this.idTypeDAO = idTypeDAO;
	}

	/**
	 * @see ar.uba.fi.posgrado.common.service.IdentificationTypeService#getById(java.lang.Long)
	 */
	public IdentificationType getById(Long idTypeId)
			throws PosgradoRuntimeException, PosgradoException {
		try {
			IdentificationType response = (IdentificationType) this.idTypeDAO
					.findById(idTypeId);
			logger.info("Tipo de documento con Id: " + idTypeId
					+ ", encontrado con exito");
			return response;
		} catch (DAOException e) {
			throw new PosgradoException(
					"Excepcion buscando el tipo de documento con Id: "
							+ idTypeId, e);
		}
	}

	public void create(IdentificationType t) throws MissingArgumentException,
			PosgradoException {
		// TODO Auto-generated method stub

	}

	public void delete(IdentificationType t) throws PosgradoRuntimeException,
			PosgradoException {
		// TODO Auto-generated method stub

	}

	/**
	 * @see ar.uba.fi.posgrado.common.service.IdentificationTypeService#getAll()
	 */
	@Transactional(readOnly = true)
	public List<IdentificationType> getAll() throws PosgradoRuntimeException,
			PosgradoException {
		try {
			List<IdentificationType> response = this.idTypeDAO.findAll();
			logger.info("Tipos de Documento encontrados: " + response.size());
			return response;
		} catch (DAOException e) {
			throw new PosgradoException(
					"Excepcion buscando tipos de documento", e);
		}
	}

	public IdentificationType update(IdentificationType t)
			throws PosgradoRuntimeException, PosgradoException {
		// TODO Auto-generated method stub
		return null;
	}

	/** 
	 * @see ar.uba.fi.posgrado.common.service.GenericService#filter(java.util.List, ar.uba.fi.posgrado.common.model.User)
	 */
	public List<IdentificationType> filter(List<IdentificationType> list,
			User user) throws PosgradoRuntimeException, PosgradoException {
		return list;
	}
	
}
